import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    keepAliveInclude: [], //需求缓存的页面列表
    menuData: [], //导航菜单
    isCollapse: false,//菜单图标方向
    pagination: {
        pagesize: 10,			// 每页条数
        pageno: 1,			// 当前页
        start: 0,			// 起始位置
        total: 0,	// 总条数
        totalpages: 0,		// 总页数
        orderby: "id",			// 排序字段
        sort: "asc",		// 排序方式
        pageSizes: [5, 10, 20, 50, 100],
        loading: false,
        loadText: '数据加载中...'
    },
    selectItems: [],//已选择表格
  },
  getters:{
    keepAliveInclude: state=> state.keepAliveInclude, 
    menuData: state=> state.menuData,
    isCollapse: state=> state.isCollapse,
    pagination: state=> state.pagination,
    selectItems: state=> state.selectItems,
  },
  mutations: {
    setKeepAliveInclude(state, moduleArray){
        state.keepAliveInclude = moduleArray;
    },
    setMenuData(state, menuData){
        state.menuData = menuData;
    },
    setIsCollapse(state, isCollapse){
        state.isCollapse = isCollapse;
    },
    setPagination(state, pagination){
        state.pagination = pagination
    },
    //分页中每页条数变化时
    sizeChange(state, pageSize) {
        if (state.pagination.pagesize != pageSize) {
            state.pagination.pagesize = pageSize;
            if (state.pageSize < 0) {
                state.pageSize = pageSize;
            }
        }
    },
    //当前页发生变化时候
    currentChange({commit, dispatch, getters}, pageNo) {
        if (pageNo !== getters.pagination.pageno) {
            commit('currentChange', pageNo);
            let data = getters.listParam
            return dispatch(getters.listType, data);
        }
    },
    setSelectItems(state, selectItems){
        state.selectItems = selectItems;
    }
  },
  actions: {

  }
})
